package com.test.common;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class MyFilter implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		HttpServletRequest req = (HttpServletRequest) request;
		HttpSession session = req.getSession();
		

		if (session.getAttribute("autadmin") != null
				|| session.getAttribute("autuser") != null) {
			chain.doFilter(request, response);
			return;

		} else {
			HttpServletResponse res = (HttpServletResponse) response;
			res.sendRedirect("/chestionar-web/faces/login.xhtml");

		}

	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void destroy() {
	}
}
